/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * VistaArticulo.java
 *
 * Created on 5/10/2011, 03:51:49 PM
 */

package Vistas;

import Beans.Articulo;
import Beans.Categoria;
import Beans.Proveedor;
import Controladores.Fecha;
import Controladores.Marticulos;
import Controladores.Mcategoria;
import Controladores.Mproveedor;
import Vistas.Menu.Menu;
import Imagenes.CtrlImagen;
import java.awt.Image;
import java.io.IOException;
import java.util.Date;
import java.util.List;
import java.util.Vector;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.DefaultListModel;
import javax.swing.ImageIcon;
import javax.swing.JFileChooser;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTable;
import javax.swing.ListSelectionModel;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;
import javax.swing.table.DefaultTableModel;

/**
 *
 * @author Leyner
 */
public class VistaArticulo extends javax.swing.JFrame {

    /** Creates new form VistaArticulo */
    Marticulos Ma = new Marticulos();
    Mproveedor Mp = new Mproveedor();
    Mcategoria Mca = new Mcategoria();
    DefaultTableModel modeloTabla = new DefaultTableModel();
    DefaultTableModel dtm = new DefaultTableModel();
    Vector<Articulo> va = new Vector<Articulo>();
    boolean condicion = false;
    boolean validacon = false;
    String nomb = "vacio";
    int fila;    
    Articulo a = new Articulo();
    Categoria c = new Categoria();
    Proveedor p = new Proveedor();

    public VistaArticulo() {
        initComponents();
    }

    public VistaArticulo(Marticulos Ma,Mproveedor Mp,Mcategoria Mca) {
        initComponents();
        this.setResizable(false);
        this.Ma=Ma;
        this.Mca=Mca;
        this.Mp=Mp;
        this.jLblCodigo.setEnabled(false);
        this.jLCategoria.setVisible(false);
        this.jCBCategorias.setVisible(false);        
        this.TablaPrincipal();
        this.TablaCategorias();
        this.DesactivarAllCampos();
    }
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new CtrlImagen("/Imagenes/a1.jpg");
        jPanelTransparente1 = new Imagenes.JPanelTransparente();
        JtxtCantidad = new javax.swing.JTextField();
        jLabel12 = new javax.swing.JLabel();
        JtxtName = new javax.swing.JTextField();
        jLblCodigo = new javax.swing.JLabel();
        jLabel13 = new javax.swing.JLabel();
        jLabel15 = new javax.swing.JLabel();
        jLabel16 = new javax.swing.JLabel();
        jTxtMinimo = new javax.swing.JTextField();
        jLabel17 = new javax.swing.JLabel();
        jLabel18 = new javax.swing.JLabel();
        jTStockMax = new javax.swing.JTextField();
        jLabel14 = new javax.swing.JLabel();
        jLabel19 = new javax.swing.JLabel();
        jLabel20 = new javax.swing.JLabel();
        jBtnLimpiar = new javax.swing.JButton();
        jDateFF = new com.toedter.calendar.JDateChooser();
        jDateFC = new com.toedter.calendar.JDateChooser();
        jDateFV = new com.toedter.calendar.JDateChooser();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jTPrecioCompra = new javax.swing.JTextField();
        jTPrecioventa = new javax.swing.JTextField();
        jScrollPane2 = new javax.swing.JScrollPane();
        jTxaObs = new javax.swing.JTextArea();
        jLabel11 = new javax.swing.JLabel();
        JBimagen = new javax.swing.JButton();
        jLblImagen1 = new javax.swing.JLabel();
        jLCategoria = new javax.swing.JLabel();
        jCBCategorias = new javax.swing.JComboBox();
        jLabel3 = new javax.swing.JLabel();
        jTextField1 = new javax.swing.JTextField();
        jComboBox1 = new javax.swing.JComboBox();
        jPanelTransparente5 = new Imagenes.JPanelTransparente();
        jBActualizar = new javax.swing.JButton();
        jBSalir1 = new javax.swing.JButton();
        jBEliminar = new javax.swing.JButton();
        jBModificar = new javax.swing.JButton();
        JBuscar = new javax.swing.JButton();
        jButton1 = new javax.swing.JButton();
        jScrollPane3 = new javax.swing.JScrollPane();
        jTableCategorias = new javax.swing.JTable();
        jLabel4 = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        jTableConsultar = new javax.swing.JTable();
        jMenuBar1 = new javax.swing.JMenuBar();
        jMenu1 = new javax.swing.JMenu();
        jSeparator1 = new javax.swing.JPopupMenu.Separator();
        jMenuItem8 = new javax.swing.JMenuItem();
        jMenu2 = new javax.swing.JMenu();
        jMenuItem1 = new javax.swing.JMenuItem();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("Interfaz Control de Articulos");

        jLabel12.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        jLabel12.setForeground(new java.awt.Color(255, 255, 255));
        jLabel12.setText("Proveedor            ");

        jLblCodigo.setFont(new java.awt.Font("Tahoma", 1, 12));
        jLblCodigo.setForeground(new java.awt.Color(255, 0, 0));

        jLabel13.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        jLabel13.setForeground(new java.awt.Color(255, 255, 255));
        jLabel13.setText("Cantidad");

        jLabel15.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        jLabel15.setForeground(new java.awt.Color(255, 255, 255));
        jLabel15.setText("Stock Maximo       ");

        jLabel16.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        jLabel16.setForeground(new java.awt.Color(255, 255, 255));
        jLabel16.setText("Stock Minimo");

        jLabel17.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        jLabel17.setForeground(new java.awt.Color(255, 255, 255));
        jLabel17.setText("Codigo:");

        jLabel18.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        jLabel18.setForeground(new java.awt.Color(255, 255, 255));
        jLabel18.setText("Nombre");

        jLabel14.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        jLabel14.setForeground(new java.awt.Color(255, 255, 255));
        jLabel14.setText("Fecha Fabricacion ");

        jLabel19.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        jLabel19.setForeground(new java.awt.Color(255, 255, 255));
        jLabel19.setText("Fecha Compra       ");

        jLabel20.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        jLabel20.setForeground(new java.awt.Color(255, 255, 255));
        jLabel20.setText("Fecha Vencimiento");

        jBtnLimpiar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Imagenes/tango-clear.png"))); // NOI18N
        jBtnLimpiar.setText("LIMPIAR ENTRADAS");
        jBtnLimpiar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jBtnLimpiarActionPerformed(evt);
            }
        });

        jLabel1.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        jLabel1.setForeground(new java.awt.Color(255, 255, 255));
        jLabel1.setText("Precio Compra");

        jLabel2.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        jLabel2.setForeground(new java.awt.Color(255, 255, 255));
        jLabel2.setText("Precio Venta");

        jTxaObs.setColumns(20);
        jTxaObs.setRows(5);
        jScrollPane2.setViewportView(jTxaObs);

        jLabel11.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        jLabel11.setForeground(new java.awt.Color(255, 255, 255));
        jLabel11.setText("Especificaciones:");

        JBimagen.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Imagenes/Picture Cast.png"))); // NOI18N
        JBimagen.setText("Imagen");
        JBimagen.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                JBimagenActionPerformed(evt);
            }
        });

        jLCategoria.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        jLCategoria.setForeground(new java.awt.Color(255, 255, 255));
        jLCategoria.setText("Categoria");

        jLabel3.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        jLabel3.setForeground(new java.awt.Color(255, 255, 255));
        jLabel3.setText("Categoria");

        jComboBox1.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jComboBox1MouseClicked(evt);
            }
        });

        javax.swing.GroupLayout jPanelTransparente1Layout = new javax.swing.GroupLayout(jPanelTransparente1);
        jPanelTransparente1.setLayout(jPanelTransparente1Layout);
        jPanelTransparente1Layout.setHorizontalGroup(
            jPanelTransparente1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanelTransparente1Layout.createSequentialGroup()
                .addGap(233, 233, 233)
                .addComponent(jLCategoria)
                .addContainerGap(489, Short.MAX_VALUE))
            .addGroup(jPanelTransparente1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanelTransparente1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanelTransparente1Layout.createSequentialGroup()
                        .addComponent(jBtnLimpiar, javax.swing.GroupLayout.DEFAULT_SIZE, 761, Short.MAX_VALUE)
                        .addContainerGap())
                    .addGroup(jPanelTransparente1Layout.createSequentialGroup()
                        .addGroup(jPanelTransparente1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanelTransparente1Layout.createSequentialGroup()
                                .addGroup(jPanelTransparente1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jLabel15)
                                    .addComponent(jLabel16))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(jPanelTransparente1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jTStockMax, javax.swing.GroupLayout.DEFAULT_SIZE, 158, Short.MAX_VALUE)
                                    .addComponent(jTxtMinimo, javax.swing.GroupLayout.DEFAULT_SIZE, 158, Short.MAX_VALUE)))
                            .addComponent(jLabel20, javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanelTransparente1Layout.createSequentialGroup()
                                .addGroup(jPanelTransparente1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jLabel18)
                                    .addComponent(jLabel12)
                                    .addComponent(jLabel13)
                                    .addComponent(jLabel17))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(jPanelTransparente1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jComboBox1, 0, 159, Short.MAX_VALUE)
                                    .addComponent(JtxtName, javax.swing.GroupLayout.DEFAULT_SIZE, 159, Short.MAX_VALUE)
                                    .addComponent(jLblCodigo, javax.swing.GroupLayout.DEFAULT_SIZE, 159, Short.MAX_VALUE)
                                    .addComponent(JtxtCantidad, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 159, Short.MAX_VALUE)))
                            .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanelTransparente1Layout.createSequentialGroup()
                                .addGroup(jPanelTransparente1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jLabel14)
                                    .addComponent(jLabel19))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(jPanelTransparente1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jDateFV, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 159, Short.MAX_VALUE)
                                    .addComponent(jDateFC, javax.swing.GroupLayout.DEFAULT_SIZE, 159, Short.MAX_VALUE)
                                    .addComponent(jDateFF, javax.swing.GroupLayout.DEFAULT_SIZE, 159, Short.MAX_VALUE))))
                        .addGap(35, 35, 35)
                        .addGroup(jPanelTransparente1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel11)
                            .addGroup(jPanelTransparente1Layout.createSequentialGroup()
                                .addGroup(jPanelTransparente1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                                    .addComponent(jCBCategorias, javax.swing.GroupLayout.Alignment.LEADING, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                    .addComponent(jScrollPane2, javax.swing.GroupLayout.Alignment.LEADING))
                                .addGap(60, 60, 60)
                                .addGroup(jPanelTransparente1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jLblImagen1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 136, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanelTransparente1Layout.createSequentialGroup()
                                        .addComponent(JBimagen, javax.swing.GroupLayout.PREFERRED_SIZE, 114, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addGap(12, 12, 12))))
                            .addGroup(jPanelTransparente1Layout.createSequentialGroup()
                                .addGroup(jPanelTransparente1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jLabel1)
                                    .addComponent(jLabel2)
                                    .addComponent(jLabel3))
                                .addGap(18, 18, 18)
                                .addGroup(jPanelTransparente1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                    .addComponent(jTextField1)
                                    .addComponent(jTPrecioventa)
                                    .addComponent(jTPrecioCompra, javax.swing.GroupLayout.DEFAULT_SIZE, 157, Short.MAX_VALUE))))
                        .addGap(98, 98, 98))))
        );
        jPanelTransparente1Layout.setVerticalGroup(
            jPanelTransparente1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanelTransparente1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanelTransparente1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel17)
                    .addComponent(jLblCodigo, javax.swing.GroupLayout.PREFERRED_SIZE, 16, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanelTransparente1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanelTransparente1Layout.createSequentialGroup()
                        .addGroup(jPanelTransparente1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel18)
                            .addComponent(JtxtName, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanelTransparente1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel13)
                            .addComponent(JtxtCantidad, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(14, 14, 14)
                        .addGroup(jPanelTransparente1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel12)
                            .addComponent(jLabel3)
                            .addComponent(jComboBox1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(18, 18, 18)
                        .addGroup(jPanelTransparente1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel16)
                            .addComponent(jTxtMinimo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 20, Short.MAX_VALUE)
                        .addGroup(jPanelTransparente1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel15)
                            .addComponent(jTStockMax, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(18, 18, 18)
                        .addGroup(jPanelTransparente1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel14)
                            .addComponent(jDateFF, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(18, 18, 18)
                        .addGroup(jPanelTransparente1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(jLabel19)
                            .addComponent(jDateFC, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(30, 30, 30)
                        .addGroup(jPanelTransparente1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jDateFV, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel20)))
                    .addGroup(jPanelTransparente1Layout.createSequentialGroup()
                        .addGroup(jPanelTransparente1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel1)
                            .addGroup(jPanelTransparente1Layout.createSequentialGroup()
                                .addComponent(jTPrecioCompra, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(jPanelTransparente1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                    .addComponent(jTPrecioventa, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 14, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 14, Short.MAX_VALUE)
                                .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(18, 18, 18)
                                .addComponent(jLabel11, javax.swing.GroupLayout.PREFERRED_SIZE, 16, javax.swing.GroupLayout.PREFERRED_SIZE)))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanelTransparente1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanelTransparente1Layout.createSequentialGroup()
                                .addComponent(jLblImagen1, javax.swing.GroupLayout.DEFAULT_SIZE, 123, Short.MAX_VALUE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(JBimagen, javax.swing.GroupLayout.PREFERRED_SIZE, 35, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 164, Short.MAX_VALUE))))
                .addGap(18, 18, 18)
                .addGroup(jPanelTransparente1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLCategoria)
                    .addComponent(jCBCategorias, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(11, 11, 11)
                .addComponent(jBtnLimpiar, javax.swing.GroupLayout.PREFERRED_SIZE, 47, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );

        jPanelTransparente5.setPreferredSize(new java.awt.Dimension(215, 431));

        jBActualizar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Imagenes/refresh.png"))); // NOI18N
        jBActualizar.setText("ACTUALIZAR");
        jBActualizar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jBActualizarActionPerformed(evt);
            }
        });

        jBSalir1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Imagenes/Desktop 2.png"))); // NOI18N
        jBSalir1.setText("SALIR");
        jBSalir1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jBSalir1ActionPerformed(evt);
            }
        });

        ListSelectionModel lssms =  jTableConsultar.getSelectionModel();
        lssms.addListSelectionListener(new ListSelectionListener(){
            public void valueChanged(ListSelectionEvent e){
                try{
                    if(e.getValueIsAdjusting())return;
                    ListSelectionModel lss=(ListSelectionModel )e.getSource();
                    if(lss.isSelectionEmpty()){
                    }else{
                        condicion=true;
                    }
                }catch(Exception z){
                }
            }
        });
        jBEliminar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Imagenes/stop.png"))); // NOI18N
        jBEliminar.setText("ELIMINAR");
        jBEliminar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jBEliminarActionPerformed(evt);
            }
        });

        ListSelectionModel lssm =  jTableConsultar.getSelectionModel();
        lssm.addListSelectionListener(new ListSelectionListener(){
            public void valueChanged(ListSelectionEvent e){
                try{
                    if(e.getValueIsAdjusting())return;
                    ListSelectionModel ls=(ListSelectionModel )e.getSource();
                    if(ls.isSelectionEmpty()){
                    }else{
                        condicion=true;
                    }
                }catch(Exception z){
                }
            }
        });
        jBModificar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Imagenes/edit.png"))); // NOI18N
        jBModificar.setText("MODIFICAR");
        jBModificar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jBModificarActionPerformed(evt);
            }
        });

        JBuscar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Imagenes/search.png"))); // NOI18N
        JBuscar.setText("BUSCAR");
        JBuscar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                JBuscarActionPerformed(evt);
            }
        });

        jButton1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Imagenes/Floppy.png"))); // NOI18N
        jButton1.setText("REGISTRAR");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanelTransparente5Layout = new javax.swing.GroupLayout(jPanelTransparente5);
        jPanelTransparente5.setLayout(jPanelTransparente5Layout);
        jPanelTransparente5Layout.setHorizontalGroup(
            jPanelTransparente5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanelTransparente5Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanelTransparente5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jBActualizar, javax.swing.GroupLayout.PREFERRED_SIZE, 195, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jBSalir1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 195, Short.MAX_VALUE)
                    .addComponent(jButton1, javax.swing.GroupLayout.DEFAULT_SIZE, 195, Short.MAX_VALUE)
                    .addComponent(jBEliminar, javax.swing.GroupLayout.DEFAULT_SIZE, 195, Short.MAX_VALUE)
                    .addComponent(jBModificar, javax.swing.GroupLayout.DEFAULT_SIZE, 195, Short.MAX_VALUE)
                    .addComponent(JBuscar, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 195, Short.MAX_VALUE))
                .addContainerGap())
        );
        jPanelTransparente5Layout.setVerticalGroup(
            jPanelTransparente5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanelTransparente5Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jBActualizar, javax.swing.GroupLayout.PREFERRED_SIZE, 47, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(29, 29, 29)
                .addComponent(JBuscar, javax.swing.GroupLayout.PREFERRED_SIZE, 47, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 28, Short.MAX_VALUE)
                .addComponent(jBModificar, javax.swing.GroupLayout.PREFERRED_SIZE, 47, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(jBEliminar, javax.swing.GroupLayout.PREFERRED_SIZE, 47, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 47, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(jBSalir1, javax.swing.GroupLayout.PREFERRED_SIZE, 47, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(25, 25, 25))
        );

        jTableCategorias.setModel(dtm);
        jTableCategorias.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jTableCategoriasMouseClicked(evt);
            }
        });
        jScrollPane3.setViewportView(jTableCategorias);

        jLabel4.setText("LISTADO DE PRODUCTOS ALMACENADOS");

        jTableConsultar.setModel(modeloTabla);
        jTableConsultar.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jTableConsultarMouseClicked(evt);
            }
        });
        jScrollPane1.setViewportView(jTableConsultar);

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(457, 457, 457)
                        .addComponent(jLabel4))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jScrollPane3, javax.swing.GroupLayout.PREFERRED_SIZE, 136, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jPanelTransparente1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(jPanelTransparente5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 1160, Short.MAX_VALUE)))
                .addContainerGap())
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jPanelTransparente1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jScrollPane3, javax.swing.GroupLayout.DEFAULT_SIZE, 429, Short.MAX_VALUE)
                    .addComponent(jPanelTransparente5, javax.swing.GroupLayout.PREFERRED_SIZE, 429, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(7, 7, 7)
                .addComponent(jLabel4)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 117, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(25, 25, 25))
        );

        jMenu1.setText("Operaciones");
        jMenu1.add(jSeparator1);

        jMenuItem8.setText("Salir");
        jMenuItem8.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem8ActionPerformed(evt);
            }
        });
        jMenu1.add(jMenuItem8);

        jMenuBar1.add(jMenu1);

        jMenu2.setText("Edicion");

        jMenuItem1.setText("Copiar");
        jMenu2.add(jMenuItem1);

        jMenuBar1.add(jMenu2);

        setJMenuBar(jMenuBar1);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jMenuItem8ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem8ActionPerformed
        // Salir
        this.dispose();
}//GEN-LAST:event_jMenuItem8ActionPerformed

    private void jBActualizarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jBActualizarActionPerformed
        // Actualizar ó cancelar
        this.Actualizar();
}//GEN-LAST:event_jBActualizarActionPerformed

    private void jBSalir1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jBSalir1ActionPerformed
        // Cerramos esta ventana
        this.dispose();
}//GEN-LAST:event_jBSalir1ActionPerformed

    private void jBEliminarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jBEliminarActionPerformed
// Eliminar
        Articulo ar = new Articulo();
        if(condicion==true){
            int question = JOptionPane.showConfirmDialog(null,"¿Seguro que desea"
                    + " eliminar este Producto?","Informacion",JOptionPane.YES_NO_OPTION);
            if(question==0){
                  ar = Ma.Consultar(Integer.parseInt(String.valueOf(modeloTabla.getValueAt(jTableConsultar.getSelectedRow(),0))));
                  int posicion = jTableConsultar.getSelectedRow();
                  modeloTabla.removeRow(posicion);
                  Ma.Eliminar(ar.getCodigo());
            }else{
                JOptionPane.showMessageDialog(null, "Peticion ca"
                        + "ncelada","Informacion",JOptionPane.INFORMATION_MESSAGE);
            }
        }else{
                String nombre = JOptionPane.showInputDialog("Digite Nombre del Producto a buscar");

                if(nombre!=null){
                       ar = this.Ma.ConsultarString(nombre);
                       
                        if(ar.getNombre().equals("")){
                            JOptionPane.showMessageDialog(null, "Este Articulo no existe");
                        } else {
                            int posicion = Ma.Posicion(ar.getCodigo()+"");
                            Ma.Eliminar(ar.getCodigo());
                            this.Actualizar();
                        }
                 }
        }
        this.condicion = false;
}//GEN-LAST:event_jBEliminarActionPerformed

    private void jBModificarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jBModificarActionPerformed
        // Modificar un Articulo
         if(jBModificar.getText().equals("MODIFICAR")){
                if(condicion==true){
                    this.ActivarAllCampos();
                    Mostrar(Ma);
                    mostrarComboCategoria();
                    jBModificar.setText("GUARDAR");
                    ImageIcon[] img_Btns = new ImageIcon[8];
                    img_Btns[0] = new ImageIcon(getClass().getResource("/Imagenes/Floppy.png"));
                    jBModificar.setIcon(img_Btns[0]);
                    jBActualizar.setText("CANCELAR");
                    JOptionPane.showMessageDialog(null, "Se han activado los campos para su edicion");
                }else{
                    nomb = JOptionPane.showInputDialog("Digite nombre del articulo");

                    if(nomb!=null){
                        a = Ma.ConsultarString(nomb);
                        if(a.getNombre().equals("")){
                            JOptionPane.showMessageDialog(null, "Este Articulo no existe");
                        } else {
                            this.mostrarnormal(a);
                            this.ActivarAllCampos();
                            mostrarComboCategoria();
                               jBModificar.setText("GUARDAR");
                                ImageIcon[] img_Btns = new ImageIcon[8];
                                img_Btns[0] = new ImageIcon(getClass().getResource("/Imagenes/Floppy.png"));
                                jBModificar.setIcon(img_Btns[0]);
                                jBActualizar.setText("CANCELAR");
                                JOptionPane.showMessageDialog(null, "Se han activado los campos para su edicion");
                        }

                     }
                }
                va.add(a);
        }else{

            Articulo art = new Articulo();
            art.setImagen(jLblImagen1.getIcon());
            art.setCodigo(Integer.parseInt(jLblCodigo.getText()));
            art.setNombre(JtxtName.getText());
            art.setCantidad(Integer.parseInt(JtxtCantidad.getText()));
            art.setStk_minimo(Integer.parseInt(jTxtMinimo.getText()));
            art.setStk_maximo(Integer.parseInt(jTStockMax.getText()));
            art.setFecha_fabricacion(jDateFF.getDate());
            art.setFecha_compra(jDateFC.getDate());
            art.setFecha_vencimiento(jDateFV.getDate());
            art.setProveedor(Mp.getProveedores().get(jComboBox1.getSelectedIndex()));
            Categoria cas =Mca.getListCategoria().get(jCBCategorias.getSelectedIndex());
            art.setCategoria(cas);
             a = va.get(0);
            Ma.Modificar(a.getNombre(), art);
            this.Actualizar();


        }

        this.condicion = false;
        a=new Articulo();
       
    }//GEN-LAST:event_jBModificarActionPerformed

    private void JBuscarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_JBuscarActionPerformed
        // Buscar Articulo especificamente
        String nombre = JOptionPane.showInputDialog("Digite Nombre del Producto a buscar");
        Articulo ar = Ma.ConsultarString(nombre);
        if(ar.getNombre().equals("")){
            JOptionPane.showMessageDialog(null, "Articulo no Encontrado");
        }else{
            this.mostrarnormal(ar);
        }

     
}//GEN-LAST:event_JBuscarActionPerformed

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        //Registrar

        if(jButton1.getText().equals("GUARDAR")){
          Fecha f_ven= new Fecha(jDateFV.getDate());
          Fecha f_com=new Fecha(jDateFC.getDate());
          Fecha f_fab=new Fecha(jDateFF.getDate());

           if(f_ven.mayor(f_com)&& f_ven.mayor(f_fab) && f_com.mayor(f_fab)){
                Articulo a = new Articulo();
                a.setImagen(jLblImagen1.getIcon());
                a.setCodigo(Integer.parseInt(jLblCodigo.getText()));
                a.setNombre(JtxtName.getText());
                a.setCantidad(Integer.parseInt(JtxtCantidad.getText()));
                a.setStk_minimo(Integer.parseInt(jTxtMinimo.getText()));
                a.setStk_maximo(Integer.parseInt(jTStockMax.getText()));
                a.setFecha_fabricacion(jDateFF.getDate());
                a.setFecha_compra(jDateFC.getDate());
                a.setFecha_vencimiento(jDateFV.getDate());
                a.setProveedor(Mp.getProveedores().get(jComboBox1.getSelectedIndex()));

                Categoria cas = cas=Mca.getListCategoria().get(jCBCategorias.getSelectedIndex());
                a.setCategoria(cas);
                Ma.Registrar(a);
                this.Actualizar();

           }else{
                JOptionPane.showMessageDialog(null, "Error en la digitalizacion"
                        + " de las fechas, por favor verifiquelas y vuelva a"
                        + " ingresarlas","Error",JOptionPane.ERROR_MESSAGE);
                 this.jDateFC.setDate(null);
                 this.jDateFF.setDate(null);
                 this.jDateFV.setDate(null);
                 }


        }else{
            this.ActivarAllCampos();
            this.mostrarComboCategoria();
            this.mostrarComboProveedor();
            this.jButton1.setText("GUARDAR");
            this.jBActualizar.setText("CANCELAR");
            ImageIcon[] img_Btns = new ImageIcon[8];
            img_Btns[0] = new ImageIcon(getClass().getResource("/Imagenes/stop_alt.png"));
            jBActualizar.setIcon(img_Btns[0]);
            this.Limpiar_Entradas();
            this.jLblCodigo.setText(this.Ma.GenerarCodigo()+"");
        }

}//GEN-LAST:event_jButton1ActionPerformed

    private void jBtnLimpiarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jBtnLimpiarActionPerformed
        Limpiar_Entradas();
}//GEN-LAST:event_jBtnLimpiarActionPerformed

    private void JBimagenActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_JBimagenActionPerformed
          JFileChooser dlg = new JFileChooser();
        //Abre la ventana de dialogo
        int option = dlg.showOpenDialog(this);
        //Si hace click en el boton abrir del dialogo
        if(option==JFileChooser.APPROVE_OPTION) {
            //Obtiene nombre del archivo seleccionado
            String file = dlg.getSelectedFile().getPath();
            jLblImagen1.setIcon(new ImageIcon(file));
            //Modificando la imagen
            ImageIcon icon = new ImageIcon(file);
            //Se extrae la imagen del icono
            Image img = icon.getImage();
            //Se modifica su tamaño
            Image newimg = img.getScaledInstance(140,170,java.awt.Image.SCALE_SMOOTH);
            //SE GENERA EL IMAGE ICON CON LA NUEVA IMAGEN
            ImageIcon newIcon = new ImageIcon(newimg);
            //Se coloca el nuevo icono modificado
            jLblImagen1.setIcon(newIcon);
            //Se cambia el tamaño de la etiqueta
            jLblImagen1.setSize(470,290);
        }
    }//GEN-LAST:event_JBimagenActionPerformed

    private void jTableCategoriasMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jTableCategoriasMouseClicked
        // Listar Tabla Segun Categoria
        this.cleanTabla();
        Categoria c = Mca.getListCategoria().get(jTableCategorias.getSelectedRow());
        for(int x =0;x<Ma.getListaarticulos().size();x++){
            Articulo a = Ma.getListaarticulos().get(x);
            if(a.getCategoria().getNombre().equals(c.getNombre())){
                Vector<String> vA = new Vector<String>();
                  vA.add(""+a.getCodigo());
                  vA.add(a.getNombre());
                  vA.add((Ma.formateador.format(a.getFecha_vencimiento())));
                  vA.add((Ma.formateador.format(a.getFecha_compra())));
                  vA.add((Ma.formateador.format(a.getFecha_fabricacion())));
                  vA.add(a.getCantidad()+"");
                  vA.add(a.getPrecio()+"");
                  modeloTabla.addRow(vA);
            }
        }
    }//GEN-LAST:event_jTableCategoriasMouseClicked

    private void jTableConsultarMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jTableConsultarMouseClicked
        // Mostrar en los campos
        this.Mostrar(Ma);
    }//GEN-LAST:event_jTableConsultarMouseClicked

    private void jComboBox1MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jComboBox1MouseClicked
        // TODO add your handling code here:
        
    }//GEN-LAST:event_jComboBox1MouseClicked


    /**
    * @param args the command line arguments
    */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new VistaArticulo().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton JBimagen;
    private javax.swing.JButton JBuscar;
    private javax.swing.JTextField JtxtCantidad;
    private javax.swing.JTextField JtxtName;
    private javax.swing.JButton jBActualizar;
    private javax.swing.JButton jBEliminar;
    private javax.swing.JButton jBModificar;
    private javax.swing.JButton jBSalir1;
    private javax.swing.JButton jBtnLimpiar;
    private javax.swing.JButton jButton1;
    private javax.swing.JComboBox jCBCategorias;
    private javax.swing.JComboBox jComboBox1;
    private com.toedter.calendar.JDateChooser jDateFC;
    private com.toedter.calendar.JDateChooser jDateFF;
    private com.toedter.calendar.JDateChooser jDateFV;
    private javax.swing.JLabel jLCategoria;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel13;
    private javax.swing.JLabel jLabel14;
    private javax.swing.JLabel jLabel15;
    private javax.swing.JLabel jLabel16;
    private javax.swing.JLabel jLabel17;
    private javax.swing.JLabel jLabel18;
    private javax.swing.JLabel jLabel19;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel20;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLblCodigo;
    private javax.swing.JLabel jLblImagen1;
    private javax.swing.JMenu jMenu1;
    private javax.swing.JMenu jMenu2;
    private javax.swing.JMenuBar jMenuBar1;
    private javax.swing.JMenuItem jMenuItem1;
    private javax.swing.JMenuItem jMenuItem8;
    private javax.swing.JPanel jPanel1;
    private Imagenes.JPanelTransparente jPanelTransparente1;
    private Imagenes.JPanelTransparente jPanelTransparente5;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JScrollPane jScrollPane3;
    private javax.swing.JPopupMenu.Separator jSeparator1;
    private javax.swing.JTextField jTPrecioCompra;
    private javax.swing.JTextField jTPrecioventa;
    private javax.swing.JTextField jTStockMax;
    private javax.swing.JTable jTableCategorias;
    private javax.swing.JTable jTableConsultar;
    private javax.swing.JTextField jTextField1;
    private javax.swing.JTextArea jTxaObs;
    private javax.swing.JTextField jTxtMinimo;
    // End of variables declaration//GEN-END:variables


    private void seguro() {
       int salir=JOptionPane.showConfirmDialog(null, ""
               + "¿Desea Registrar otro Articulo"
               + "?","Cerrar",JOptionPane.YES_NO_OPTION);
         if(salir ==1){
         this.dispose();
    }
    }


    private void Mostrar(Marticulos Ma) {
        Articulo ar = Ma.Consultar(Integer.parseInt(String.valueOf(
        modeloTabla.getValueAt(jTableConsultar.getSelectedRow(),0))));
        jLblCodigo.setText(ar.getCodigo()+"");
        jLblImagen1.setIcon(ar.getImagen());
        JtxtName.setText(ar.getNombre());
        jTextField1.setText(ar.getCategoria().getNombre());
        JtxtCantidad.setText(ar.getCantidad()+"");
        jTxtMinimo.setText(ar.getStk_minimo()+"");
        jTStockMax.setText(ar.getStk_maximo()+"");
        jTPrecioCompra.setText(ar.getPrecio_compra()+"");
        jTPrecioventa.setText(ar.getPrecio()+"");
        jDateFF.setDate(ar.getFecha_fabricacion());
        jDateFC.setDate(ar.getFecha_compra());
        jDateFV.setDate(ar.getFecha_vencimiento());
        jComboBox1.removeAllItems();
        mostrarComboProveedor();
        jComboBox1.setSelectedIndex(Ma.Posicion(ar.getNombre()));
      

    }

    public void mostrarnormal(Articulo ar){

        jLblCodigo.setText(ar.getCodigo()+"");
        jLblImagen1.setIcon(ar.getImagen());
        JtxtName.setText(ar.getNombre());
        jTextField1.setText(ar.getCategoria().getNombre());
        JtxtCantidad.setText(ar.getCantidad()+"");
        jTxtMinimo.setText(ar.getStk_minimo()+"");
        jTStockMax.setText(ar.getStk_maximo()+"");
        jTPrecioCompra.setText(ar.getPrecio_compra()+"");
        jTPrecioventa.setText(ar.getPrecio()+"");
        jDateFF.setDate(ar.getFecha_fabricacion());
        jDateFC.setDate(ar.getFecha_compra());
        jDateFV.setDate(ar.getFecha_vencimiento());
        jComboBox1.removeAllItems();
        mostrarComboProveedor();
        jComboBox1.setSelectedIndex(Ma.Posicion(ar.getNombre()));
       

    }
    private void Actualizar() {
        this.dispose();
        VistaArticulo Va = new VistaArticulo(Ma,Mp,Mca);
        Va.setLocationRelativeTo(null);
        Va.setVisible(true);
    }

    private void DesactivarAllCampos() {
        JtxtCantidad.setEditable(false);
        JtxtName.setEditable(false);
        jTPrecioCompra.setEditable(false);
        jTPrecioventa.setEditable(false);
        jTStockMax.setEditable(false);
        jTxaObs.setEditable(false);
        jTxtMinimo.setEditable(false);
        jComboBox1.setEnabled(false);
        jDateFC.setEnabled(false);
        jDateFF.setEnabled(false);
        jDateFV.setEnabled(false);
        JBimagen.setEnabled(false);
    }
    private void ActivarAllCampos() {
        JtxtCantidad.setEditable(true);
        JtxtName.setEditable(true);
        jTPrecioCompra.setEditable(true);
        jTPrecioventa.setEditable(true);
        jTStockMax.setEditable(true);
        jTxaObs.setEditable(true);
        jTxtMinimo.setEditable(true);
        jComboBox1.setEnabled(true);
        jDateFC.setEnabled(true);
        jDateFF.setEnabled(true);
        jDateFV.setEnabled(true);
        JBimagen.setEnabled(true);
        jCBCategorias.setVisible(true);
        jLCategoria.setVisible(true);
        jLblCodigo.setText(Ma.GenerarCodigo()+"");
        jLabel3.setVisible(false);
        jTextField1.setVisible(false);
    }


    public void mostrarComboProveedor(){
        for(int x=0; x<Mp.getProveedores().size();x++){
            jComboBox1.addItem(Mp.getProveedores().get(x).getNombre());
        }
    }

       public void mostrarComboCategoria(){
        for(int x=0; x<Mca.getListCategoria().size();x++){
            jCBCategorias.addItem(Mca.getListCategoria().get(x).getNombre());
        }
    }

       public void Limpiar_Entradas(){
        jLblCodigo.setText("");
        JtxtCantidad.setText("");
        JtxtName.setText("");
        jTPrecioCompra.setText("");
        jTPrecioventa.setText("");
        jTStockMax.setText("");
        jTxaObs.setText("");
        jTxtMinimo.setText("");
        jComboBox1.setSelectedIndex(0);
        jDateFC.setDate(null);
        jDateFF.setDate(null);
        jDateFV.setDate(null);
        jLblImagen1.setIcon(null);

       }

       public void cleanTabla(){

        modeloTabla=(DefaultTableModel) jTableConsultar.getModel();
        int x=modeloTabla.getRowCount();
        for(int i=-1;i<(x-1);i++)
                modeloTabla.removeRow(0);

  }

    private void TablaPrincipal() {
        modeloTabla.addColumn("CODIGO");
        modeloTabla.addColumn("NOMBRE");
        modeloTabla.addColumn("  FECHA-VENCIMIENTO  ");
        modeloTabla.addColumn("    FEHCA-COMPRA   ");
        modeloTabla.addColumn("   FECHA-FABRICACION   ");
        modeloTabla.addColumn("CANTIDAD");
        modeloTabla.addColumn("PRECIO");

        for(int x=0;x<Ma.getListaarticulos().size();x++){
            Vector<String> vA = new Vector<String>();
             a = Ma.getListaarticulos().get(x);
             vA.add(""+a.getCodigo());
             vA.add(a.getNombre());
             vA.add((Ma.formateador.format(a.getFecha_vencimiento())));
             vA.add((Ma.formateador.format(a.getFecha_compra())));
             vA.add((Ma.formateador.format(a.getFecha_fabricacion())));
             vA.add(a.getCantidad()+"");
             vA.add(a.getPrecio()+"");
             modeloTabla.addRow(vA);
        }
    }

    private void TablaCategorias() {
        dtm.addColumn("Categorias");

         for(int x=0;x<Mca.getListCategoria().size();x++){
            Vector<String> v = new Vector<String>();
             c = Mca.getListCategoria().get(x);
             v.add(""+c.getNombre());
             dtm.addRow(v);
        }
    }

      

}
